package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import model.Drawing;
import util.DbUtil;

public class DrawingDao {
	
	//添加一期开奖号码
	public int addDrawing(Drawing drawing){
	    int flag=0;
		DbUtil dbutil=new DbUtil();
		Connection con = dbutil.dbcon();
		String sqls="insert into drawing (programId,red_1,red_2,red_3,red_4,red_5,red_6,blue) value (?,?,?,?,?,?,?,?)";
		PreparedStatement ps=null;
		try {
			ps=con.prepareStatement(sqls);
			ps.setInt(1,drawing.getProgramId());
			ps.setInt(2, drawing.getRed_1());
			ps.setInt(3, drawing.getRed_2());
			ps.setInt(4, drawing.getRed_3());
			ps.setInt(5, drawing.getRed_4());
			ps.setInt(6, drawing.getRed_5());
			ps.setInt(7, drawing.getRed_6());
			ps.setInt(8, drawing.getBlue());
			flag=ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		dbutil.closecon(ps, null);
		return flag;
	}	
	
	//删除一期开奖号码
	public int delDawingById(int programId){
		DbUtil dbutil=new DbUtil();
		Connection con = dbutil.dbcon();
		String sqls="delete from drawing (programId) value (?,)";
		PreparedStatement ps=null;
		try {
			ps=con.prepareStatement(sqls);
			ps.setInt(1, programId);
			programId=ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		dbutil.closecon(ps, null);
		return programId;	
	}		

}
